package 算法.base.juc;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @author lchenglong
 * @date 2022/5/12
 */
public class CompletableFutureTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        final CompletableFuture<String> future = new CompletableFuture<>();
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                future.complete("我处理完了...");
            }
        });
        thread.start();
        long start = System.currentTimeMillis();
        String result = future.get();
        long end = System.currentTimeMillis();
        System.out.println("耗时:" + (end - start)+"ms");
        System.out.println(result);
    }
}
